<?php
require_once('functions.php');

require_once('lib/nusoap.php');
$server = new soap_server();
$server->configureWSDL('GeoService', 'urn:GeoService');

$server->wsdl->addComplexType(
		'Contact', 
		'complexType',
		'struct',
		'all',
		'',
		array( 'id' => array('name' => 'id', 'type' => 'xsd:int'),
			'name' => array('name' => 'name', 'type' => 'xsd:string'),
			'last_seen' => array('name' => 'last_seen', 'type' => 'xsd:string'),
			'position' => array('name' => 'position', 'type' => 'xsd:string')
			)
		);
		
$server->wsdl->addComplexType(
		'ContactList',
		'complexType',
		'array',
		'',
		'SOAP-ENC:Array',
		array(),
		array(
			array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:Contact[]')
			),
		'tns:Contact'
		);

$server->wsdl->addComplexType(
		'Message', 
		'complexType',
		'struct',
		'all',
		'',
		array( 'id' => array('name' => 'id', 'type' => 'xsd:int'),
			'sender' => array('name' => 'sender', 'type' => 'xsd:string'),
			'time' => array('name' => 'time', 'type' => 'xsd:string'),
			'body' => array('name' => 'body', 'type' => 'xsd:string')
			)
		);
		
$server->wsdl->addComplexType(
		'MessageList',
		'complexType',
		'array',
		'',
		'SOAP-ENC:Array',
		array(),
		array(
			array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:Message[]')
			),
		'tns:Message'
		);		

$server->register("Register",
		array('user' => 'xsd:string', 'pass' => 'xsd:string'),
		array('return' => 'xsd:string'),
		'urn:GeoService',
		'urn:GeoService#Register',
		'rpc',
		'encoded',
		'Adds new user to the database.');

$server->register("AddFollower",
		array('user' => 'xsd:string', 'pass' => 'xsd:string', 'friend' => 'xsd:string'),
		array('return' => 'xsd:string'),
		'urn:GeoService',
		'urn:GeoService#AddFollower',
		'rpc',
		'encoded',
		'Adds new follower.');
		
$server->register("RemoveFollower",
		array('user' => 'xsd:string', 'pass' => 'xsd:string', 'friend' => 'xsd:string'),
		array('return' => 'xsd:string'),
		'urn:GeoService',
		'urn:GeoService#RemoveFollower',
		'rpc',
		'encoded',
		'Removes follower.');

$server->register("GetContactList",
		array('user' => 'xsd:string', 'pass' => 'xsd:string'),
		array('return' => 'tns:ContactList'),
		'urn:GeoService',
		'urn:GeoService#GetContactList',
		'rpc',
		'encoded',
		'Returns the positions of the contact list members.');
		
$server->register("UpdatePosition",
		array('user' => 'xsd:string', 'pass' => 'xsd:string', 'gprmc' => 'xsd:string', 'logged' => 'xsd:boolean'),
		array('return' => 'xsd:string'),
		'urn:GeoService',
		'urn:GeoService#UpdatePosition',
		'rpc',
		'encoded',
		'Updates the contact position with the given GPRMC sentence.');

$server->register("SendMessage",
		array('user' => 'xsd:string', 'pass' => 'xsd:string', 'nameUserTo' => 'xsd:string', 'message' => 'xsd:string'),
		array('return' => 'xsd:string'),
		'urn:GeoService',
		'urn:GeoService#SendMessage',
		'rpc',
		'encoded',
		'Send message to a friend.');
		
$server->register("GetMessages",
		array('user' => 'xsd:string', 'pass' => 'xsd:string'),
		array('return' => 'tns:MessageList'),
		'urn:GeoService',
		'urn:GeoService#GetMessages',
		'rpc',
		'encoded',
		'Returns a list of Message structures.');
		
$server->register("SetTwitterName",
		array('user' => 'xsd:string', 'pass' => 'xsd:string', 'twittername' => 'xsd:string'),
		array('return' => 'xsd:string'),
		'urn:GeoService',
		'urn:GeoService#SetTwitterName',
		'rpc',
		'encoded',
		'Sets Twitter name for the user.');
		
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);


?>